<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索框 -->
      <el-row>
        <el-col :span="6">
          <el-input placeholder="请输入内容">
            <!-- 搜索按钮 -->
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 订单列表 -->
      <el-table :data="orderList" style="width: 100%" stripe border>
        <!-- 索引 -->
        <el-table-column type="index" label="#"></el-table-column>
        <!-- 订单编号 -->
        <el-table-column prop="order_number" label="订单编号" width="200px"> </el-table-column>
        <!-- 订单价格 -->
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <!-- 是否支付 -->
        <el-table-column label="是否支付">
          <template #default="scope">
            <el-tag type="success" v-if="scope.row.order_pay + '' === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <!-- 是否发货 -->
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <!-- 下单时间 -->
        <el-table-column label="下单时间">
          <template #default="scope">
            {{ scope.row.update_time | dateFormat }}
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作">
          <template #default="">
            <!-- 编辑 -->
            <el-button type="primary" icon="el-icon-edit" @click="dialogAddressFormVisible = true"></el-button>
            <!-- 定位 -->
            <el-button type="success" icon="el-icon-location" @click="showProgress"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.total"
        background
      >
      </el-pagination>
    </el-card>
    <!-- 收货地址选择对话框 -->
    <el-dialog title="收货地址" :model="addressForm" ref="addressFormRef" :visible.sync="dialogAddressFormVisible" width="50%">
      <el-form label-position="left" label-width="80px">
        <el-form-item label="省市区/县">
          <!-- 省市区选择器 -->
          <el-cascader :options="cityData" v-model="addressForm.addressArr"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址">
          <!-- 详细地址输入框 -->
          <el-input v-model="addressForm.addressDetail"></el-input>
        </el-form-item>
      </el-form>
      <!-- 页脚 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAddressFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogAddressFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog title="物流进度" :model="progressForm" ref="progressFormRef" :visible.sync="progressVisible" width="50%">
      <el-timeline :reverse="reverse">
        <el-timeline-item v-for="(activity, index) in activities" :key="index" :timestamp="activity.timestamp">
          {{ activity.content }}
        </el-timeline-item>
      </el-timeline>
      <!-- 页脚 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="progressVisible = false">取 消</el-button>
        <el-button type="primary">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  created () {
    this.getOrderList()
  },
  methods: {
    /* 获取订单列表 */
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    /* 每页显示条数改变时 */
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    /* 当前页码改变时 */
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    /* 定位按钮点击事件 */
    async showProgress () {
      this.progressVisible = true
    }
  },
  data () {
    return {
      /* 订单列表对象 */
      orderList: [],
      /* 请求订单列表的参数对象 */
      queryInfo: {
        /* 查询参数 */
        query: '',
        /* 当前页码 */
        pagenum: 1,
        /* 每页显示条数 */
        pagesize: 10
        /* 用户ID */
      },
      /* 页码总数 */
      total: 0,
      /* 控制对话框是否显示 */
      dialogAddressFormVisible: false,
      /* 修改地址表单数组 */
      addressForm: {
        /* 详细地址 */
        addressDetail: '',
        /* 级联选择器地址数组 */
        addressArr: []
      },
      /* 省市区信息 */
      cityData: cityData,
      /* 物流进度对话框表单对象 */
      progressForm: {},
      /* 控制物流进度对话框的显示与否 */
      progressVisible: false,
      /* 时间轴对象 */
      activities: [
        {
          timestamp: '2021 - 4 - 1',
          content: '完成Vue'
        },
        {
          timestamp: '2021 - 4 - 1',
          content: '完成Vue'
        },
        {
          timestamp: '2021 - 4 - 1',
          content: '完成Vue'
        },
        {
          timestamp: '2021 - 4 - 1',
          content: '完成Vue'
        }
      ]
    }
  }
}
</script>

<style lang="less" scoped>
.el-breadcrumb {
  font-size: 12px;
  margin-bottom: 20px;
}
.el-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15) !important;
}
</style>
